﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Blazing.WebFacade;
using Blazing.Web.Util;

namespace Blazing.WebShop.UserControls
{
    public partial class DisplayTagCategories : System.Web.UI.UserControl
    {
        public int TaxonomyID
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (TaxonomyID > 0)
            {
                var controller = new ProductsController();
                var list = controller.TagsAttachedToProducts(TaxonomyID);

                var orderedList = from i in list
                                  orderby i.Tag.Name
                                  select new { Url = UrlFormatter.FormatUrl("/category/"+i.Slug+"/"), Name = i.Tag.Name };

                RepeaterTags.DataSource = orderedList.ToList();
                RepeaterTags.DataBind();
            }
        }
    }
}